package lab02.test21;

import java.util.Scanner;

public class Test21 {
    public static void main(String[] args) {
        //统计一个字符串中给定字符出现的频率。
        //假定统计5
        int count=0;      //计算频率

        Scanner strings = new Scanner(System.in);
        System.out.println("请给定字符串:");
        String string = strings.next();

        outer:while(true) {
            System.out.println("是否要进行频率统计？");
            System.out.println("1.是");
            System.out.println("2.否");
            int choose = strings.nextInt();
            switch(choose) {
                case 1:
                    {
                    System.out.println("请输入要统计频率的字符:");
                    String ch = strings.next();
                    for (int i = 0;i < string.length();i++) {
                        char temp = string.charAt(i);
                        if (ch.compareTo(String.valueOf(temp)) == 0) {
                            count++;
                        }
                    }
                    System.out.println("字符" + ch + "共出现了" + count + "次！");
                    break;
            }
                case 2:
                    break outer;
            }
        }
    }
}
